package studentmanagement;

import java.util.ArrayList;
import java.util.List;

public class Student {
    private String id;
    private String name;
    private String gender;
    private List<Course> selectedCourses = new ArrayList<>();  // 已选课程列表

    // 构造方法
    public Student(String id, String name, String gender) {
        this.id = id;
        this.name = name;
        this.gender = gender;
    }

    // 选课方法
    public void selectCourse(Course course) {
        if (!selectedCourses.contains(course)) {
            selectedCourses.add(course);
            System.out.println(name + "选择了《" + course.getCourseName() + "》");
        } else {
            System.out.println(name + "已选过《" + course.getCourseName() + "》，无需重复选择");
        }
    }

    // 退课方法
    public void dropCourse(Course course) {
        if (selectedCourses.remove(course)) {
            System.out.println(name + "退选了《" + course.getCourseName() + "》");
        } else {
            System.out.println(name + "未选择《" + course.getCourseName() + "》，无法退选");
        }
    }

    // 打印已选课程
    public void showSelectedCourses() {
        System.out.println("\n" + name + "的已选课程：");
        if (selectedCourses.isEmpty()) {
            System.out.println("暂无选课记录");
            return;
        }
        for (Course course : selectedCourses) {
            System.out.println("课程ID：" + course.getId() +
                    "，课程名：" + course.getCourseName() +
                    "，教师：" + course.getTeacher().getName() +
                    "，时间：" + course.getTime() +
                    "，地点：" + course.getLocation());
        }
    }

    // getter和setter
    public String getId() { return id; }
    public void setId(String id) { this.id = id; }
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    public String getGender() { return gender; }
    public void setGender(String gender) { this.gender = gender; }
}